package com.ecoolex.ying.space.api.graphql;

import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.common.pojo.Sorting;
import com.ecoolex.framework.modularize.api.auth.user.ConsumerMemberAuthority;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.ying.space.entity.GoodsLabel;
import com.ecoolex.ying.space.pojo.QueryGoodsLabelDTO;
import com.ecoolex.ying.space.ws.GoodsService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import java.util.List;

import static com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type.User;

@GraphQL2Module(type = User, description = "商品标签")
public class GoodsLabelGraphql {

    @Reference
    private GoodsService goodsService;
    @Autowired
    private StorageService storageService;


    @QueryField(field = "goodsLabel", description = "获取商品标签详情")
    public GoodsLabel get(@NonNull Integer labelId, ConsumerMemberAuthority user) {
        user.assertLogin();
        return goodsService.getLabelById(labelId);
    }

    @QueryField(field = "goodsLabelList", description = "查询商品标签列表")
    public Pagination<GoodsLabel> query(@NonNull QueryGoodsLabelDTO query, @NonNull Sorting[] sorts, @NonNull Page page, ConsumerMemberAuthority user) {
        user.assertLogin();
        return goodsService.queryLabel(query, sorts, page);
    }

    @QueryField(field = "goodsLabelAllList", description = "查询所有商品标签列表")
    public List<GoodsLabel> goodsLabelAllList(ConsumerMemberAuthority user) {
        user.assertLogin();
        return goodsService.queryAllLabel();
    }
}
